#!/usr/bin/env python

def bubble_sort(nums):
    for i in range(len(nums) - 1, -1, -1):
        switched = False
        for j in range(i):
            if nums[j] > nums[j + 1]:
                switched = True
                nums[j + 1], nums[j] = nums[j], nums[j + 1]
        
        if not switched:
            break
    
    return nums


if __name__ == "__main__":
    import random
    nums = [random.randint(0, 100) for _ in range(20)]

    print(nums)
    print(bubble_sort(nums))
